/**
 * race的使用场景
 * 图片加载超时
 * 脚本加载超时
 */


const p1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('数据正常返回')
    },3000)
})

const wrap = p1 => {
    let abort;
    const p = new Promise((resolve, reject) => {
        abort = reject
    });

    const p2 = Promise.race([p1, p]);
    p2.abort = abort
    return p2
}

const p2 = wrap(p1)

p2.then(data => { console.log(data) }, err => { console.log(err) });

setTimeout(() => {
    p2.abort('超过一秒了')
}, 1000)